home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / asm3.zip / PARINT.ASM next >
Assembly Source File  |  1986-02-05  |  7KB  |  204 lines

  1. comment *  Parint.com - (C) 1984 by David G Hunter.
  2.            This program may be freely copied but may not be sold for profit.
  3.  
  4.            Parint.Com is a program that detects parity errors, logs them on the 
  5.            printer if possible, beeps, and returns to program execution.  The 
  6.            system does not halt when this program is resident.  Parity error 
  7.            checking is terminated after first error is detected.  The error 
  8.            message includes the time of the event.  If the printer is not 
  9.            available, errors are logged to the screen. 
  10. *
  11. ;*************** Addresses of Interrupt handlers *******************
  12.  
  13. Book    segment at 0h   ;this is where the interrupt address book is
  14.         org     2h*4    ;
  15. Int_2   label   dword   ;address of NMI handler
  16. Book    ends
  17.  
  18. ;*************** Beginning of Parint Instructions *******************
  19. cseg    segment
  20.         assume cs:cseg
  21.         org 100h
  22.  
  23. Start:  jmp newvec      ;install new NMI handler in RAM
  24.  
  25.  
  26. ;************************ NMI handler *******************************
  27.  
  28. newint  proc    near    ;new interrupt handler
  29.         assume ds:cseg, es:cseg
  30.         sti             ;this flag was cleared when interrupt was issued
  31.         jmp     go      ;jump over more data
  32.  
  33. ;---------------------------- DATA -----------------------------------
  34.  
  35. GetOut: nop
  36. Instruc db      0EAh    ;this is the jump-immediate instruction!
  37.                         ;it jumps to the address stored in oldint.
  38. Oldint  dd              ;address of old interrupt 2 routine - 
  39. Device1 dw      0004    ;printer
  40. Device2 dw      0001    ;standard output device
  41. par1    db      0Dh,0Ah,"Parity Error: Main Board     ",07h,0Dh,0Ah
  42. par2    db      0Dh,0Ah,"Parity Error: Expansion Board",07h,0Dh,0Ah
  43. time    db      "    TIME:  "
  44. hour    dw      "00"
  45.         db      ":"
  46. min     dw      "00"
  47.         db      "                ",0Dh,0Ah
  48. paroff  db      "PARITY CHECKING NOW DISABLED   ",0Dh,0Ah,0Ah
  49.  
  50.  
  51. ;--------------------------- MAIN PROGRAM --------------------------
  52.  
  53. go:     push    cx
  54.         push    ds
  55.         pushf
  56.         push    dx
  57.         push    bx
  58.         push    ax
  59.         pushf
  60.         mov     al, 00h
  61.         out     0A0h, al        ;turn off parity checking for now
  62.         xor     cx, cx          ;cx=error flag: cx=1 if parity OK
  63.         in      al, 62h         ;get data in port C 
  64.  
  65. ; - - find origin of NMI - - - - - -
  66.         test    al, 40h 
  67.         jz      mother  
  68.         mov     dx, offset par2 ;if bit 6 set, error is on expansion board
  69.         jmp     out             ;print message and exit
  70.  
  71. mother: test    al, 80h 
  72.         jz      other   
  73.         mov     dx, offset par1 ;if bit 7 set, error is on main board
  74.         jmp     out             ;print message and exit
  75.  
  76. other:  or      cx, 1h          ;If neither bit set, no parity error occurred,
  77.         mov     al, 80h         ;so set parity OK flag
  78.         out     0A0h, al        ;turn parity checking back on.
  79.         jmp     noprt           ;Dont print message if no parity error.
  80.  
  81. ; - - print error message and exit.  Type of exit depends on type of error - -
  82. out:    mov     ax,cs           ;establish proper data segment to
  83.         mov     ds,ax           ; allow access to messages
  84.         call    whatime         ;get time of error
  85.         mov     bx, device1
  86.         cmp     bx,0004         ;if output is to printer, make sure its ready
  87.         jne     f1
  88.         call    testprt
  89. f1:     call    print
  90.         mov     dx, offset time ;"time of error" message
  91.         call    print
  92.         mov     dx, offset paroff
  93.         call    print
  94.  
  95. noprt:  popf
  96.         pop     ax
  97.         pop     bx
  98.         pop     dx
  99.         popf
  100.         pop     ds
  101.         test    cx, 1h          ;special exit if parity OK
  102.         jnz     oth
  103.         pop     cx
  104.         iret                    ;message printed; let execution continue
  105.  
  106. ;     If no parity error, turn control over to pre-existing NMI handler.
  107. ; This is done by restoring DS and jumping to the instruction that
  108. ; specifies the address of the old interrupt routine.  This unusual exit
  109. ; is necessary because otherwise, once DS was restored, the address of the 
  110. ; old interrupt routine would not be accesible.
  111.  
  112. oth:    cli
  113.         pop     cx
  114.         jmp     GetOut 
  115.  
  116. newint  endp
  117.  
  118.  
  119. ;************************ SUBROUTINES ********************************
  120.  
  121. Testprt proc near
  122.         push    dx
  123.         push    ax
  124.         xor     dx,dx           ;printer # 0
  125.         mov     ah,2
  126.         int     17h             ;read printer status
  127.         test    ah,00101001b    ;error bits
  128.         jz      aok
  129.         mov     bx, device2     ;if not ok, try other device
  130. aok:    pop     ax
  131.         pop     dx
  132.         ret
  133. testprt endp
  134.  
  135. Print   proc    near    ;output to file named in bx; if error try another file
  136.         push    cx
  137.         mov     cx,34   ;34 characters to print
  138.         mov     ah,40h  ;DOS function call
  139.         int     21h
  140.         pop     cx
  141.         ret
  142. print   endp
  143.  
  144. Whatime proc    near    ;what time is it?  put result in hour/min
  145.         push    cx
  146.         push    dx
  147.         mov     ah,2Ch  ;DOS time
  148.         int     21h
  149.         mov     al,ch   ;hours (0-23)
  150.         call    convt   ;put tens in ah, ones in al
  151.         mov     hour,"00"
  152.         add     hour,ax
  153.         mov     al,cl
  154.         call    convt   ;do same for minutes (0-59)
  155.         mov     min,"00"
  156.         add     min,ax
  157.         pop     dx
  158.         pop     cx
  159.         ret
  160. whatime endp
  161.  
  162. Convt   proc    near    ;convert number (<100) to ASCII.  Number is in al.
  163.                         ;result:  tens in ah, ones in al.
  164.         xor     ah,ah   ;input is less than 100 anyway, so clear it
  165.         push    cx
  166.         mov     cl,10
  167.         div     cl      ;divide ax by 10
  168.         pop     cx
  169. little: ret
  170. convt   endp
  171.  
  172.                   
  173. ;*********************** INSTALL NMI HANDLER *******************
  174.  
  175. Newvec  proc    near
  176.         jmp     past
  177.  
  178. loaded  db      0Dh,0Ah,"PARITY ERROR INTERCEPTOR v2.00 by David Hunter IS NOW"
  179.         db      " INSTALLED",0Dh,0Ah,"$" 
  180.  
  181. past:   mov     dx, offset loaded
  182.         mov     ah,9
  183.         int     21h
  184.         assume  ds:Book         ;interrupt address book area
  185.         push    ds              ;save old ds for future use
  186.         mov     ax,Book
  187.         mov     ds,ax
  188.         mov     al, 00h
  189.         out     0A0h, al        ;turn off parity checking
  190.         mov     ax,int_2        ;get the address
  191.         mov     oldint,ax       ;save it for some future use
  192.         mov     ax,int_2[2]     ;second part of double word
  193.         mov     oldint[2],ax
  194.         mov     int_2, offset newint    ;now load the new address
  195.         mov     int_2[2],cs             ;cs is ds in com program
  196.         mov     al, 80h
  197.         out     0A0h, al                ;turn parity checking back on
  198.         mov     dx, offset newvec       ;leave new interrupt routine resident
  199.         int     27h                     ;don't need "newvec" or beyond
  200. newvec  endp
  201. cseg    ends
  202.         end     start
  203.  
  204.